<?php

use think\migration\Migrator;

class CreateTableSystemUser extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = \common\extra\MigrateFast::get(
            $this->table('system_user'),
            [
                ['username', 'string', ['comment' => '用户名', 'limit' => 30]],
                ['password', 'string', ['comment' => '密码', 'limit' => 60]],
                ['nickname', 'string', ['comment' => '昵称', 'default' => '', 'limit' => 30]],
                ['avatar', 'string', ['comment' => '头像', 'default' => '', 'limit' => 255]],
                ['phone', 'char', ['comment' => '手机号码', 'default' => '', 'limit' => 11]],
                ['email', 'string', ['comment' => '邮箱地址', 'default' => '', 'limit' => 50]],
                ['status', 'integer', ['comment' => '状态 0 禁用 forbid 1 启用 open', 'default' => 0, 'limit' => 50]],
            ],
            [
                'username' => ['unique' => true, 'name' => 'username']
            ]
        );

        $table->create();
    }
}
